package com.buddies.lottery.base;

import com.buddies.lottery.data.BusEvent;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * 接收RxBus事件的Fragment基类
 * Created by liuleigang on 2018/3/12.
 */

public abstract class BaseBusEventFragment<P extends IPresenter> extends BaseFragment<P> {
    protected Disposable mDisposable;

    @Override
    public void onResume() {
        mDisposable = RxBus.get().register(BusEvent.class, new Consumer<BusEvent>() {
            @Override
            public void accept(BusEvent event) throws Exception {
                onBusEvent(event);
            }
        });
        super.onResume();
    }

    protected void onBusEvent(BusEvent event) {

    }

    @Override
    public void onPause() {
        if (mDisposable != null) {
            RxBus.get().unregister(mDisposable);
        }
        super.onPause();
    }

}
